unit Unit5;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, CheckLst, Menus;

type
  TForm5 = class(TForm)
    Panel1: TPanel;
    Button1: TButton;
    Button2: TButton;
    Edit1: TEdit;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Panel2: TPanel;
    ListBox1: TCheckListBox;
    Memo1: TMemo;
    Button6: TButton;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    MainMenu1: TMainMenu;
    LastFm1: TMenuItem;
    N1: TMenuItem;
    procedure Button2Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure Edit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure ListBox1DblClick(Sender: TObject);
    procedure ComboBox1Select(Sender: TObject);
    procedure ComboBox2Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form5: TForm5;

implementation

uses apiGetHTTP, zHttpgetTopTrack, procedures, main, zHttpPiterFm;

{$R *.dfm}

procedure TForm5.Button1Click(Sender: TObject);
var i:integer;
    l:TListItem;
begin
for i := 0 to ListBox1.items.Count - 1 do   begin
if(listbox1.Checked[i]) then begin
l:= formMa.thlist.Items.Add;
l.ImageIndex:=thlistImgWaitSearch;
l.Caption:=inttostr(l.Index);
l.SubItems.Add(ListBox1.Items[i]);
listbox1.ItemEnabled[i]:=false;
listbox1.Checked[i]:=false;

end;
end;
end;

procedure TForm5.Button2Click(Sender: TObject);
begin
form5.ListBox1.Clear;
//zHttpgetTopTrack
gethttp:=tgethttp.create(true);
gethttp.par1 := Edit1.Text;
gethttp.URL:='http://ws.audioscrobbler.com/2.0/?method=artist.gettoptracks&artist=' + URLEncode(edit1.Text) + '&api_key=b25b959554ed76058ac220b7b2e0a026';
gethttp.CallBack:=zHttpgetTopTrackEvent;
gethttp.ErrorCallback:=zHttpgetTopTrackError;
//gethttp.ProgressCallback:=zHttpgetTopTrackProgress;
gethttp.Resume();

end;

procedure loadPiterFM(URL:string) ;
begin
form5.ListBox1.Clear;
gethttp:=tgethttp.create(true);
gethttp.URL:=URL;
gethttp.CallBack:=zHttpPiterFMEvent;
gethttp.ErrorCallback:=zHttpPiterFMError;
gethttp.Resume();
end;

procedure TForm5.Button3Click(Sender: TObject);
begin
//zHttpPiterFM
loadPiterFM('http://www.piter.fm/charts/top100');

end;

procedure TForm5.Button5Click(Sender: TObject);
begin
//zHttpmoskvaFM
 loadPiterFM('http://www.moskva.fm/charts/top100');

end;

procedure TForm5.Button6Click(Sender: TObject);
begin
ListBox1.Items := Memo1.Lines;
end;

procedure TForm5.ComboBox1Select(Sender: TObject);
var URL:string;
begin
URL := ComboBox1.Text;
URL := 'http://www.piter.fm/stations/' + Copy(URL, pos('-',URL)+2, length(URL)-pos('-',URL)) + '/top100'   ;
loadPiterFM(URL);
ListBox1.SetFocus;
end;

procedure TForm5.ComboBox2Change(Sender: TObject);
var URL:string;
begin
URL := ComboBox2.Text;
URL := 'http://www.moskva.fm/stations/' + Copy(URL, pos('-',URL)+2, length(URL)-pos('-',URL)) + '/top100'   ;
loadPiterFM(URL);
ListBox1.SetFocus;
end;

procedure TForm5.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if key=13 then
button2.click();
end;

procedure TForm5.FormActivate(Sender: TObject);
begin
edit1.SetFocus();

end;

procedure TForm5.ListBox1DblClick(Sender: TObject);
var i:integer;
begin
//find selected item
i := 0;

while( (i < ListBox1.Count) and not listbox1.selected[i]) do inc(i);
ListBox1.Checked[i] := true;
Button1.Click;

end;

end.
